package com.pleasantwalk.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class MakeRequestTest implements EntryPoint {
  EntryPoint entryPoint = this;
  VerticalPanel vPanel = null;
  public void handleResponse(BreakfastResponse br) {
    //this.breakfastResponse = br;
     HTML html = new HTML(br.getTitle());
     vPanel.add(html);
  }
  native void callMakeRequest(EntryPoint ep) /*-{
    $wnd["response"] = function(obj) {
      ep.@com.pleasantwalk.client.MakeRequestTest::handleResponse(Lcom/pleasantwalk/client/BreakfastResponse;)(obj);
    };
    var params = {};  
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.DOM;  
    var url = "http://doc.examples.googlepages.com/breakfast-data.xml";  
    gadgets.io.makeRequest(url, response, params);
  }-*/;
  /**
   * This is the entry point method.
   */
  public void onModuleLoad() {
    Button button = new Button("call makeRequest");

    //callMakeRequest(entryPoint);

    vPanel = new VerticalPanel();
    vPanel.setWidth("100%");
    vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
    vPanel.add(button);

    // Add image and button to the RootPanel
    RootPanel.get().add(vPanel);

    button.addClickListener(new ClickListener() {
      public void onClick(Widget sender) {
        callMakeRequest(entryPoint);
      }
    });
  }
}
